﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using FlexCell;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKAreaStatistic.DataDefine;
using YJKAreaStatistic.Manage;
using YJKRevitBase.StringUtility;
using YJKExcelTableUtil;
using YJKMaterialStatistic;
using YJKRevitKernel.FormUtility.ModelessFormControlSuite;
using YJKRevitKernel.FormUtility.ModelessFormControlSuite.ModelLayer;
using YJKGeometryFuncs;

namespace YJKAreaStatistic.Forms
{
    public partial class AreaStatisticResultForm : System.Windows.Forms.Form, IModelessFormNoneSwitch
	{
		public IWin32Window RevitHandle
		{
			get
			{
				return this.m_revitHandle;
			}
			private set
			{
				this.m_revitHandle = value;
			}
		}

		public bool IfContinue
		{
			get
			{
				return this.m_bIfContinue;
			}
		}

		public bool IfBreak
		{
			get
			{
				return this.m_bIfBreak;
			}
		}

		public bool IfManualEsc
		{
			get
			{
				return this.m_bIfManuEsc;
			}
		}

		public UIDocument UiDoc
		{
			get
			{
				return this.m_uiDoc;
			}
			set
			{
				this.m_uiDoc = value;
			}
		}

		public AreaStatisticResultForm(ExternalCommandData commandData, IWin32Window inputHandle, UIDocument inputUidoc)
		{
			this.m_revit = commandData;
			this.UiDoc = commandData.Application.ActiveUIDocument;
			this.m_doc = commandData.Application.ActiveUIDocument.Document;
			this.m_revitHandle = inputHandle;
			this.InitializeComponent();
			this.TableDataInit();
			this.TableDesign();
		}

		private void AreaStatisticResultForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.lbrowInfo.Visible = false;
			this.lbRowVal.Visible = false;
			if (this.ResultGrid.Cols < 12)
			{
				this.mouseRight.Items[1].Enabled = false;
			}
		}

		private void ResultGrid_MouseClick(object sender, MouseEventArgs e)
		{
			int lastRow = this.ResultGrid.Selection.LastRow;
			int lastCol = this.ResultGrid.Selection.LastCol;
			if (Untiltiy.m_lstMergeRow.Contains(lastRow) && lastCol >= 5)
			{
				this.ResultGrid.ContextMenuStrip = null;
				return;
			}
			if (e.Button == MouseButtons.Right)
			{
				this.ResultGrid.ContextMenuStrip = this.mouseRight;
			}
		}

		private void AddtoolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.ResultGrid.Cols++;
			this.m_lstAddCols.Add(this.ResultGrid.Cols - 1);
			this.m_nMostColNum = this.ResultGrid.Cols - 1;
			this.RefreshTableCell();
			if (this.ResultGrid.Cols > 11)
			{
				this.mouseRight.Items[1].Enabled = true;
			}
		}

		private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
		{
			int lastCol = this.ResultGrid.Selection.LastCol;
			int tableColNum = this.GetTableColNum();
			if (lastCol < tableColNum)
			{
				YJKMessageBox.Show("无法删除初始数据!");
				return;
			}
			this.ResultGrid.Column(lastCol).Delete();
			if (this.m_lstAddCols.Contains(lastCol))
			{
				this.m_lstAddCols.Remove(lastCol);
			}
			else
			{
				List<int> list = new List<int>();
				foreach (int num in this.m_lstAddCols)
				{
					list.Add(num - 1);
				}
				this.m_lstAddCols.Clear();
				this.m_lstAddCols.AddRange(list);
			}
			if (this.ResultGrid.Cols < 12)
			{
				this.mouseRight.Items[1].Enabled = false;
			}
		}

		private void ResultGrid_Click(object Sender, EventArgs e)
		{
			int lastRow = this.ResultGrid.Selection.LastRow;
			int lastCol = this.ResultGrid.Selection.LastCol;
			this.m_nModifyCellRow = lastRow;
			this.m_nModifyCellCol = lastCol;
			if (Untiltiy.m_lstFixedCol.Contains(lastCol) || Untiltiy.m_lstFixedRow.Contains(lastRow))
			{
				return;
			}
			if (Untiltiy.m_lstMergeRow.Contains(lastRow) && lastCol >= 5)
			{
				return;
			}
			this.ResultGrid.Cell(lastRow, lastCol).Locked = true;
			if (Untiltiy.m_lstBaseDataRow.Contains(lastRow))
			{
				this.lbrowInfo.Visible = false;
				this.lbRowVal.Visible = false;
				this.groupBox1.Visible = false;
				this.tvSubArea.Visible = true;
			}
			else
			{
				this.lbrowInfo.Visible = true;
				this.lbRowVal.Visible = true;
				this.groupBox1.Visible = true;
				this.tvSubArea.Visible = false;
			}
			this.ShowSubArea(lastRow, lastCol, null);
		}

		private void ResultGrid_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			int lastRow = this.ResultGrid.Selection.LastRow;
			int lastCol = this.ResultGrid.Selection.LastCol;
			if (Untiltiy.m_lstFixedCol.Contains(lastCol))
			{
				return;
			}
			if (!Untiltiy.m_lstBanDoubleClickRow.Contains(lastRow))
			{
				return;
			}
			this.m_nClickCellRow = lastRow;
			this.m_nClickCellCol = lastCol;
			this.ResultGrid.Cell(this.m_nClickCellRow, this.m_nClickCellCol).Locked = false;
			this.m_strCellText = this.ResultGrid.Cell(this.m_nClickCellRow, this.m_nClickCellCol).Text;
		}

		private void ResultGrid_LeaveCell(object Sender, FlexCell.Grid.LeaveCellEventArgs e)
		{
			if (e.Text != this.m_strCellText && e.Row == this.m_nClickCellRow && e.Col == this.m_nClickCellCol)
			{
				Cell cell = this.ResultGrid.Cell(e.Row, e.Col);
				if (e.Text == "")
				{
					YJKMessageBox.Show("输入为空, 请重新输入数字!");
					return;
				}
				if (e.Text != null && !this.BeInteger(e.Text))
				{
					cell.Text = this.m_strCellText;
					YJKMessageBox.Show("非法输入, 请重新输入数字!");
					return;
				}
				cell.Locked = true;
				cell.BackColor = System.Drawing.Color.Gainsboro;
				string text = cell.Text;
				if (e.Row == 3)
				{
					string text2 = this.ResultGrid.Cell(e.Row, 1).Text;
					string text3 = this.ResultGrid.Cell(2, e.Col).Text;
					this.lstRecordCells.Add(new List<string>
					{
						text2,
						text3,
						text
					});
				}
				else if (e.Row == 4)
				{
					string text4 = this.ResultGrid.Cell(e.Row, 2).Text;
					string text5 = this.ResultGrid.Cell(2, e.Col).Text;
					this.lstRecordCells.Add(new List<string>
					{
						text4,
						text5,
						text
					});
				}
				try
				{
					BaseCellData cellData = this.tableManager.GetCellData(this.m_nClickCellRow, this.m_nClickCellCol);
					if (cellData != null)
					{
						cellData.CellValue = text;
						foreach (BaseCellData baseCellData in this.tableManager.GetUpdateCellData(cellData))
						{
							try
							{
								this.ResultGrid.Cell(baseCellData.RowNum, baseCellData.ColumnNum).Text = baseCellData.CellValue;
							}
							catch (Exception)
							{
							}
						}
					}
				}
				catch (Exception)
				{
				}
			}
		}

		private void RefreshBtn_Click(object sender, EventArgs e)
		{
			this.TableDataInit();
			for (int i = 0; i < this.ResultGrid.Rows; i++)
			{
				for (int j = 4; j < this.ResultGrid.Cols; j++)
				{
					if (this.ResultGrid.Cell(i, j).BackColor == System.Drawing.Color.Gainsboro)
					{
						this.ResultGrid.Cell(i, j).BackColor = System.Drawing.Color.White;
					}
				}
			}
		}

		private void ExportBtn_Click(object sender, EventArgs e)
		{
			if (this.IfExistIllegalVal())
			{
				return;
			}
			try
			{
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.FileName = Untiltiy.m_strExportFileName;
				saveFileDialog.Filter = "Excel文件|*.xls|盈建科表格文件|*.hybg";
				if (saveFileDialog.ShowDialog() == DialogResult.OK)
				{
					try
					{
						File.OpenWrite(saveFileDialog.FileName).Close();
					}
					catch (Exception)
					{
						MessageBox.Show("请先关闭当前导入文档!", "提示");
						base.DialogResult = DialogResult.Cancel;
						return;
					}
					for (int i = 1; i < this.ResultGrid.Rows; i++)
					{
						for (int j = 1; j < this.ResultGrid.Cols; j++)
						{
							this.ResultGrid.Cell(i, j).Locked = false;
						}
					}
					for (int k = 1; k < this.ResultGrid.Cols; k++)
					{
						this.ResultGrid.Column(k).Locked = false;
					}
					this.ResultGrid.Range(1, 1, this.ResultGrid.Rows - 1, this.ResultGrid.Cols - 1).ClearBackColor();
					this.ResultGrid.ExportToExcel(saveFileDialog.FileName, false, false);
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("导出失败");
			}
			base.Close();
		}

		private void DrawTableBtn_Click(object sender, EventArgs e)
		{
			if (this.IfExistIllegalVal())
			{
				return;
			}
			this.m_bIfContinue = false;
			this.m_bIfBreak = true;
			this.m_bIfManuEsc = true;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCloseMethodMethod = new AreaStatisticResultForm.BeforeCloseMethod(this.Export);
		}

		private void Export()
		{
			try
			{
				this.m_gridSet.GridName = Untiltiy.m_strExportFileName;
				CREATENEWVIEW newView = CREATENEWVIEW.EXIST;
				new GridToolExportImportRevit(this.m_revit, this.ResultGrid, Untiltiy.m_strExportFileName, this.m_gridSet.LineWidthOut, this.m_gridSet.LineWidthInner, newView).DrawInRevitView();
			}
			catch (Exception)
			{
				YJKMessageBox.Show("统计失败");
			}
		}

		private void CloseBtn_Click(object sender, EventArgs e)
		{
			base.Close();
			this.SendEscMessageToRevitAndClearSelect();
		}

		private void AreaStatisticResultForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			try
			{
				this.m_lstAddCols = this.m_lstAddCols.Distinct<int>().ToList<int>();
				foreach (int num in this.m_lstAddCols)
				{
					if (num < this.ResultGrid.Cols)
					{
						List<string> list = new List<string>();
						for (int i = 2; i < this.ResultGrid.Rows; i++)
						{
							if (i != 11 || i != 23)
							{
								string text = this.ResultGrid.Cell(i, num).Text;
								if (string.IsNullOrEmpty(text))
								{
									text = Untiltiy.m_strDefaultVal;
								}
								list.Add(text);
							}
						}
						this.m_lstaddColData.Add(num, list);
					}
				}
				if (this.m_lstaddColData.Count != 0 || this.lstRecordCells.Count != 0)
				{
					Transaction transaction = new Transaction(this.m_doc, "AddCol");
					try
					{
						transaction.Start();
						InsertDataManager.WriteExtensibleStorage(this.m_doc, this.m_lstaddColData);
						InsertDataManager.WriteFormRecordData(this.m_doc, this.lstRecordCells);
						transaction.Commit();
					}
					catch (Exception)
					{
						transaction.RollBack();
						YJKMessageBox.Show("新增数据列保存失败!");
					}
				}
				this.SendEscMessageToRevitAndClearSelect();
			}
			catch
			{
			}
		}

		private void AreaStatisticResultForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (this.controller == null)
			{
				return;
			}
			Transaction transaction = new Transaction(this.m_doc, "DeleteDrawCurve");
			try
			{
				transaction.Start();
				this.IsSaveSingleCurve(this.controller.m_lstDetailCurveId, this.lstNewArea);
				if (this.lstSaveSingleCv.Count != 0 && YJKMessageBox.Show("存在已经绘制的面积边界未生成面积，请问是否保存该边界", MessageBoxButtons.YesNo) == DialogResult.No)
				{
					this.m_doc.Delete(this.controller.m_lstDetailCurveId);
				}
				else
				{
					this.m_doc.Delete(this.lstDeleteCv);
					foreach (ElementId elementId in this.lstSaveSingleCv)
					{
						InsertDataManager.WriteExensibleStorageToCurve(this.m_doc.GetElement(elementId), true);
					}
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
				YJKMessageBox.Show("删除绘制线失败!");
			}
		}

		private void ModifyBtn_Click(object sender, EventArgs e)
		{
			if (this.ResultGrid.Cell(this.m_nModifyCellRow, this.m_nModifyCellCol).BackColor == System.Drawing.Color.Gainsboro)
			{
				YJKMessageBox.Show("自定义数据后不再关联面积平面!");
				return;
			}
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new AreaStatisticResultForm.BeforeContinueMethod(this.ModifyAreaBoundary);
		}

		private void CheckBtn_Click(object sender, EventArgs e)
		{
			if (this.ResultGrid.Cell(this.m_nModifyCellRow, this.m_nModifyCellCol).BackColor == System.Drawing.Color.Gainsboro)
			{
				YJKMessageBox.Show("自定义数据后不再关联面积平面!");
				return;
			}
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.ShowAreaPlan(DoType.DT_Check);
		}

		private void tvSubArea_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			this.m_bIfContinue = true;
			this.m_bIfBreak = false;
			this.m_bIfManuEsc = false;
			this.SendEscMessageToRevitAndClearSelect();
			this.m_useBeforeCotinueMethod = new AreaStatisticResultForm.BeforeContinueMethod(this.LocationMethod);
		}

		private void tvSubArea_AfterSelect(object sender, TreeViewEventArgs e)
		{
			TreeNode selectedNode = this.tvSubArea.SelectedNode;
			this.ShowAttributeTable(selectedNode.Tag as BaseCellData);
		}

		public void ShowForm(IWin32Window parentForm = null)
		{
			if (this.RevitHandle != null)
			{
				base.Show(this.RevitHandle);
				return;
			}
			base.Show();
		}

		public void CloseForm()
		{
			if (!base.IsDisposed)
			{
				base.Close();
			}
		}

		public void ResetContinueBreak()
		{
			this.m_bIfContinue = false;
			this.m_bIfBreak = true;
			this.m_bIfManuEsc = true;
		}

		public void SendEscMessageToRevitAndClearSelect()
		{
			this.m_useBeforeCotinueMethod = null;
			RevitVersionFuncs.ClearSelection(this.UiDoc.Selection);
			Utility.SendEscToHandle(this.RevitHandle);
		}

		public void DoBeforeContinue()
		{
			if (this.m_useBeforeCotinueMethod != null)
			{
				this.m_useBeforeCotinueMethod();
			}
		}

		public void DoBeforeColse()
		{
			if (this.m_useBeforeCloseMethodMethod != null)
			{
				this.m_useBeforeCloseMethodMethod();
			}
		}

		private void ModifyAreaBoundary()
		{
			if (Untiltiy.m_lstBaseDataRowNoModify.Contains(this.m_nModifyCellRow))
			{
				YJKMessageBox.Show("当前行属性不支持修改边界!");
				return;
			}
			if (!this.ShowAreaPlan(DoType.DT_Modify))
			{
				return;
			}
			base.Hide();
			if (SelectAreaManager._hWndRevit == null)
			{
				SelectAreaManager._hWndRevit = CmdAreaStatistic._hWndRevit;
			}
			this.controller = new SelectAreaManager(this.m_revit, false);
			if (this.controller.EditOutLine() != null)
			{
				YJKMessageBox.Show("绘制区域失败");
				base.Close();
				return;
			}
			if (this.controller.m_lstDetailCurveId.Count == 0 && this.controller.m_lstSelectRooms.Count == 0)
			{
				base.Show();
				return;
			}
			this.controller.m_lstDetailCurveId.AddRange(ModifyBonudaryManager.GetDetailCurve(this.m_doc));
			List<Room> list = new List<Room>();
			List<ElementId> list2 = new List<ElementId>();
			List<Curve> list3 = new List<Curve>();
			foreach (ElementId elementId in this.controller.m_lstDetailCurveId)
			{
				list3.Add((this.m_doc.GetElement(elementId) as DetailCurve).GeometryCurve);
			}
			foreach (Element element in this.controller.m_lstSelectRooms)
			{
				list.Add(element as Room);
				list2.Add(element.Id);
			}
			if (this.controller.IfClose)
			{
				base.Show();
			}
			ModifyBonudaryManager.ClearUpCaching();
			double num = 0.0;
			List<KeyValuePair<Area, AreaBoundaryBean>> list4 = new List<KeyValuePair<Area, AreaBoundaryBean>>();
			foreach (Element element2 in new FilteredElementCollector(this.m_doc, this.m_doc.ActiveView.Id).OfClass(typeof(SpatialElement)))
			{
				Area area = element2 as Area;
				if (area != null)
				{
					List<ElementId> inputIds = new List<ElementId>();
					num += area.Area;
					List<Curve> oneAreaBoundaryCurves = ModifyBonudaryManager.GetOneAreaBoundaryCurves(this.m_doc, area, this.m_nClickCellRow, ref inputIds);
					list4.Add(new KeyValuePair<Area, AreaBoundaryBean>(area, new AreaBoundaryBean(oneAreaBoundaryCurves, inputIds)));
				}
			}
			this.lstNewArea.Clear();
			Transaction transaction = new Transaction(this.m_doc, "CreateNewArea");
			List<Area> list5 = new List<Area>();
			try
			{
				transaction.Start();
				if (!ModifyBonudaryManager.GetAreaInfo(this.m_revit, list3, list, this.m_nModifyCellRow, list4, ref list5, ref this.lstNewArea))
				{
					transaction.RollBack();
				}
				else
				{
					transaction.Commit();
					foreach (Area area2 in list5)
					{
						num -= area2.Area;
					}
					this.RefreshCellData(num, this.lstNewArea, list);
				}
			}
			catch (Exception)
			{
				transaction.RollBack();
			}
		}

		private void IsSaveSingleCurve(List<ElementId> lstDrawCurve, List<Area> lstNewArea)
		{
			List<Curve> list = new List<Curve>();
			List<ElementId> list2 = new List<ElementId>();
			foreach (Area area in lstNewArea)
			{
				list.AddRange(ModifyBonudaryManager.GetOneAreaBoundaryCurves(this.m_doc, area, this.m_nClickCellRow, ref list2));
			}
			foreach (ElementId elementId in lstDrawCurve)
			{
				bool flag = false;
				try
				{
					Curve geometryCurve = (this.m_doc.GetElement(elementId) as DetailCurve).GeometryCurve;
					foreach (Curve curve in list)
					{
						if (Geometry.IsEqual(geometryCurve.Length, curve.Length, 0.001))
						{
							flag = true;
						}
					}
					if (flag)
					{
						this.lstDeleteCv.Add(elementId);
					}
					else
					{
						this.lstSaveSingleCv.Add(elementId);
					}
				}
				catch (Exception)
				{
				}
			}
		}

		private void LocationMethod()
		{
			TreeNode selectedNode = this.tvSubArea.SelectedNode;
			Document document = this.UiDoc.Document;
			ElementSet elementSet = new ElementSet();
			List<Element> selElements = new List<Element>();
			if (this.IfIsLevelNode(selectedNode))
			{
				this.ChangeNowViewPlan(selectedNode, document);
			}
			else if (selectedNode.Tag is Room)
			{
				this.ChangeNowViewPlan(selectedNode.Parent, document);
				this.AdpatNodeInformation(selectedNode, ref elementSet, ref selElements);
			}
			if (elementSet.Size > 0)
			{
				this.UiDoc.ShowElements(elementSet);
				RevitVersionFuncs.SetSelection(this.UiDoc.Selection, selElements);
				this.UiDoc.RefreshActiveView();
			}
		}

		private void AdpatNodeInformation(TreeNode oneNode, ref ElementSet useSet, ref List<Element> lstElement)
		{
			Element element = null;
			if (oneNode.Tag is Room)
			{
				element = (oneNode.Tag as Room);
			}
			if (element != null)
			{
				useSet.Insert(element);
				lstElement.Add(element);
			}
		}

		private bool ChangeNowViewPlan(TreeNode nowNode, Autodesk.Revit.DB.Document useDoc)
		{
			try
			{
				if (nowNode.Tag is BaseCellData)
				{
					Level genLevel = (nowNode.Tag as BaseCellData).CurUseAreaPlan.GenLevel;
				}
				else if (nowNode.Tag is Room)
				{
					Level level = (nowNode.Tag as Room).Level;
				}
				this.UiDoc.ActiveView = (nowNode.Tag as BaseCellData).CurUseAreaPlan;
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private bool IfIsLevelNode(TreeNode nowNode)
		{
			return nowNode.Tag is BaseCellData;
		}

		private void TableDesign()
		{
			this.ResultGrid.Row(0).Height = 0;
			this.ResultGrid.Column(0).Width = 0;
			this.AttributeTableShow.Row(0).Height = 0;
			this.AttributeTableShow.Column(0).Width = 0;
			this.AttributeTableShow.Column(1).Width = 60;
			this.AttributeTableShow.Column(2).Width = 84;
			System.Drawing.Rectangle bounds = Screen.PrimaryScreen.Bounds;
			int height = bounds.Height;
			if (bounds.Width >= 3840 && height >= 2160)
			{
				this.ResultGrid.Column(2).Width = 150;
				this.ResultGrid.Column(3).Width = 110;
			}
			else
			{
				this.ResultGrid.Column(2).Width = 110;
				this.ResultGrid.Column(3).Width = 80;
			}
			this.ResultGrid.Column(1).Width = 60;
			this.ResultGrid.Row(1).Height = 22;
			this.ResultGrid.Row(11).Height = 22;
			this.ResultGrid.Row(23).Height = 22;
			this.ResultGrid.Row(2).Height = 28;
			this.ResultGrid.Row(13).Height = 28;
			this.AttributeTableShow.Row(1).Height = 25;
			this.AttributeTableShow.Row(2).Height = 28;
			this.AttributeTableShow.Row(3).Height = 28;
			this.ResultGrid.Cell(1, 1).Text = "单元指标";
			this.ResultGrid.Cell(1, 1).BackColor = System.Drawing.Color.BurlyWood;
			this.ResultGrid.Cell(2, 1).Text = "各类不同特征的楼层编号";
			this.ResultGrid.Cell(2, 1).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(2, 3).Text = "单位";
			this.ResultGrid.Cell(3, 1).Text = "各类不同特征楼层层数";
			this.ResultGrid.Cell(3, 1).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(3, 3).Text = "层";
			this.ResultGrid.Cell(4, 1).Text = "建筑工程面积计算";
			this.ResultGrid.Cell(4, 1).BackColor = System.Drawing.Color.Gainsboro;
			this.ResultGrid.Cell(4, 2).Text = "各层建筑面积";
			this.ResultGrid.Cell(4, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(5, 2).Text = "各层总建筑面积";
			this.ResultGrid.Cell(5, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(6, 2).Text = "地上建筑面积";
			this.ResultGrid.Cell(7, 2).Text = "地下建筑面积";
			this.ResultGrid.Cell(8, 2).Text = "总建筑面积";
			this.ResultGrid.Cell(8, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(9, 2).Text = "总套内面积";
			this.ResultGrid.Cell(9, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(10, 2).Text = "总公摊面积";
			this.ResultGrid.Cell(10, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(11, 1).Text = "户型指标";
			this.ResultGrid.Cell(11, 1).BackColor = System.Drawing.Color.BurlyWood;
			this.ResultGrid.Cell(12, 1).Text = "分类";
			this.ResultGrid.Cell(12, 1).BackColor = System.Drawing.Color.Gainsboro;
			this.ResultGrid.Cell(12, 2).Text = "户型编号";
			this.ResultGrid.Cell(13, 2).Text = "户型所在位置";
			this.ResultGrid.Cell(14, 2).Text = "各种户型数量";
			this.ResultGrid.Cell(15, 2).Text = "套内面积";
			this.ResultGrid.Cell(16, 1).Text = "其中";
			this.ResultGrid.Cell(16, 1).BackColor = System.Drawing.Color.Gainsboro;
			this.ResultGrid.Cell(16, 2).Text = "半面积区域1";
			this.ResultGrid.Cell(16, 2).BackColor = System.Drawing.Color.LightCyan;
			this.ResultGrid.Cell(17, 2).Text = "半面积区域2(手动)";
			this.ResultGrid.Cell(17, 2).BackColor = System.Drawing.Color.LightCyan;
			this.ResultGrid.Cell(18, 2).Text = "半面积区域3(手动)";
			this.ResultGrid.Cell(18, 2).BackColor = System.Drawing.Color.LightCyan;
			this.ResultGrid.Cell(19, 2).Text = "分项合计";
			this.ResultGrid.Cell(20, 1).BackColor = System.Drawing.Color.Gainsboro;
			this.ResultGrid.Cell(20, 2).Text = "总套内建筑面积";
			this.ResultGrid.Cell(20, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(21, 2).Text = "套内使用面积";
			this.ResultGrid.Cell(21, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(22, 2).Text = "总使用面积";
			this.ResultGrid.Cell(22, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(23, 1).Text = "套型指标";
			this.ResultGrid.Cell(23, 1).BackColor = System.Drawing.Color.BurlyWood;
			this.ResultGrid.Cell(24, 1).Text = "套型指标";
			this.ResultGrid.Cell(24, 1).BackColor = System.Drawing.Color.Gainsboro;
			this.ResultGrid.Cell(24, 2).Text = "单元公共公摊面积";
			this.ResultGrid.Cell(24, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(25, 2).Text = "销售面积";
			this.ResultGrid.Cell(25, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(26, 2).Text = "套型面积";
			this.ResultGrid.Cell(26, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(27, 2).Text = "其中";
			this.ResultGrid.Cell(27, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(27, 3).Text = "公共公摊系数";
			this.ResultGrid.Cell(27, 3).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(28, 3).Text = "公共公摊面积";
			this.ResultGrid.Cell(28, 3).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(29, 3).Text = "楼层公摊系数";
			this.ResultGrid.Cell(29, 3).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(30, 3).Text = "楼层公摊面积";
			this.ResultGrid.Cell(30, 3).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(31, 2).Text = "赠送面积";
			this.ResultGrid.Cell(31, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(32, 2).Text = "赠送比";
			this.ResultGrid.Cell(32, 2).BackColor = System.Drawing.Color.Lavender;
			this.ResultGrid.Cell(33, 2).Text = "产权出房率";
			this.ResultGrid.Cell(33, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(34, 2).Text = "产权得房率";
			this.ResultGrid.Cell(34, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(35, 2).Text = "实际出房率";
			this.ResultGrid.Cell(35, 2).BackColor = System.Drawing.Color.Bisque;
			this.ResultGrid.Cell(36, 2).Text = "实际得房率";
			this.ResultGrid.Cell(36, 2).BackColor = System.Drawing.Color.Bisque;
			this.AttributeTableShow.Cell(1, 1).Text = "面积平面";
			this.AttributeTableShow.Cell(2, 1).Text = "视图名称";
			this.AttributeTableShow.Cell(3, 1).Text = "标高";
			this.AttributeTableShow.Cell(4, 1).Text = "区域合计";
			for (int i = 2; i < 37; i++)
			{
				if (i < 4)
				{
					this.ResultGrid.Range(i, 1, i, 2).Merge();
				}
				else if ((i > 23 && i < 27) || i > 30)
				{
					this.ResultGrid.Range(i, 2, i, 3).Merge();
				}
			}
			this.m_nMostColNum--;
			this.ResultGrid.Range(1, 1, 1, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(4, 1, 10, 1).Merge();
			this.ResultGrid.Range(11, 1, 11, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(12, 1, 15, 1).Merge();
			this.ResultGrid.Range(16, 1, 19, 1).Merge();
			this.ResultGrid.Range(20, 1, 22, 1).Merge();
			this.ResultGrid.Range(24, 1, 36, 1).Merge();
			this.ResultGrid.Range(23, 1, 23, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(27, 2, 30, 2).Merge();
			int num = this.GetTableColNum();
			if (num <= this.m_nMostColNum)
			{
				num = this.m_nMostColNum;
			}
			this.ResultGrid.Range(6, 5, 10, num).Merge();
			this.ResultGrid.Range(20, 5, 20, num).Merge();
			this.ResultGrid.Range(22, 5, 22, num).Merge();
			this.ResultGrid.Range(24, 5, 24, num).Merge();
			this.ResultGrid.Range(33, 5, 33, num).Merge();
			this.ResultGrid.Range(35, 5, 35, num).Merge();
			for (int j = 0; j < this.ResultGrid.Rows; j++)
			{
				for (int k = 0; k < this.ResultGrid.Cols; k++)
				{
					if (j > 3 && j < 23 && k == 3)
					{
						this.ResultGrid.Cell(j, k).Text = "m^2";
					}
					this.ResultGrid.Cell(j, k).Alignment = AlignmentEnum.CenterCenter;
					this.ResultGrid.Cell(j, k).WrapText = true;
				}
			}
			for (int l = 0; l < this.AttributeTableShow.Rows; l++)
			{
				for (int m = 0; m < this.AttributeTableShow.Cols; m++)
				{
					this.AttributeTableShow.Cell(l, m).Alignment = AlignmentEnum.CenterCenter;
				}
			}
			for (int n = 0; n < this.ResultGrid.Rows; n++)
			{
				if (!Untiltiy.m_lstBanDoubleClickRow.Contains(n))
				{
					for (int num2 = 0; num2 < this.ResultGrid.Cols; num2++)
					{
						this.ResultGrid.Cell(n, num2).Locked = true;
					}
				}
			}
			this.ResultGrid.Cell(12, 3).Text = "";
			this.ResultGrid.Cell(13, 3).Text = "";
			this.ResultGrid.Cell(14, 3).Text = "个";
			this.ResultGrid.Column(1).Locked = true;
			this.ResultGrid.Column(2).Locked = true;
			this.ResultGrid.Column(3).Locked = true;
			for (int num3 = 2; num3 < this.ResultGrid.Rows; num3++)
			{
				if (num3 < 23)
				{
					this.ResultGrid.Range(num3, 1, num3, 2).set_Borders(EdgeEnum.Inside, LineStyleEnum.Thin);
				}
				else
				{
					this.ResultGrid.Range(num3, 1, num3, 3).set_Borders(EdgeEnum.Inside, LineStyleEnum.Thin);
				}
			}
			this.ResultGrid.Range(1, 2, 22, 2).set_Borders(EdgeEnum.Outside, LineStyleEnum.Thin);
			this.ResultGrid.Range(23, 3, 36, 3).set_Borders(EdgeEnum.Outside, LineStyleEnum.Thin);
			this.ResultGrid.Range(1, 1, 1, this.m_nMostColNum).set_Borders(EdgeEnum.Outside, LineStyleEnum.Thick);
			this.ResultGrid.Range(11, 1, 11, this.m_nMostColNum).set_Borders(EdgeEnum.Outside, LineStyleEnum.Thick);
			this.ResultGrid.Range(23, 1, 23, this.m_nMostColNum).set_Borders(EdgeEnum.Outside, LineStyleEnum.Thick);
		}

		private void RefreshTableCell()
		{
			this.ResultGrid.Locked = false;
			this.ResultGrid.Column(1).Locked = false;
			this.ResultGrid.Column(2).Locked = false;
			this.ResultGrid.Column(3).Locked = false;
			this.ResultGrid.Row(1).Locked = false;
			this.ResultGrid.Row(23).Locked = false;
			for (int i = 0; i < this.ResultGrid.Rows; i++)
			{
				for (int j = 0; j < this.ResultGrid.Cols; j++)
				{
					this.ResultGrid.Cell(i, j).Locked = false;
				}
			}
			this.ResultGrid.Range(1, 1, 1, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(11, 1, 11, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(23, 1, 23, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(6, 5, 10, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(20, 5, 20, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(22, 5, 22, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(24, 5, 24, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(33, 5, 33, this.m_nMostColNum).Merge();
			this.ResultGrid.Range(35, 5, 35, this.m_nMostColNum).Merge();
			for (int k = 0; k < this.ResultGrid.Rows; k++)
			{
				if (!Untiltiy.m_lstBanDoubleClickRow.Contains(k))
				{
					for (int l = 0; l < this.ResultGrid.Cols; l++)
					{
						this.ResultGrid.Cell(k, l).Locked = true;
					}
				}
			}
			for (int m = 2; m < this.ResultGrid.Rows; m++)
			{
				for (int n = 10; n < this.ResultGrid.Cols - 1; n++)
				{
					this.ResultGrid.Range(m, n, m, n).set_Borders(EdgeEnum.Right, LineStyleEnum.None);
				}
			}
		}

		private void TableDataInit()
		{
			int num = 0;
			int num2 = 0;
			List<BaseCellData> list = new List<BaseCellData>();
			List<RecordCellData> lstRecordDatas = new List<RecordCellData>();
			InsertDataManager.ReadFormRecordData(this.m_doc, ref lstRecordDatas);
			this.tableManager = new TableDataManager(this.m_doc);
			this.tableManager.InitData(lstRecordDatas, ref num2, ref num);
			this.m_nMostColNum = ((num2 > num) ? num2 : num);
			this.m_nMostColNum = ((this.m_nMostColNum > 11) ? this.m_nMostColNum : 11);
			this.ResultGrid.Cols = this.m_nMostColNum;
			foreach (BaseCellData baseCellData in this.tableManager.LstTotalTargetData)
			{
				this.ResultGrid.Cell(baseCellData.RowNum, baseCellData.ColumnNum).Text = baseCellData.CellValue;
				if (baseCellData.BIsModify)
				{
					list.AddRange(this.tableManager.GetUpdateCellData(baseCellData));
					this.ResultGrid.Cell(baseCellData.RowNum, baseCellData.ColumnNum).BackColor = System.Drawing.Color.Gainsboro;
				}
			}
			foreach (BaseCellData baseCellData2 in this.tableManager.LstHouseTargetData)
			{
				this.ResultGrid.Cell(baseCellData2.RowNum, baseCellData2.ColumnNum).Text = baseCellData2.CellValue;
			}
			foreach (BaseCellData baseCellData3 in this.tableManager.LstCoverTargetData)
			{
				this.ResultGrid.Cell(baseCellData3.RowNum, baseCellData3.ColumnNum).Text = baseCellData3.CellValue;
			}
			foreach (BaseCellData baseCellData4 in list)
			{
				this.ResultGrid.Cell(baseCellData4.RowNum, baseCellData4.ColumnNum).Text = baseCellData4.CellValue;
			}
			IDictionary<int, string> dictionary = new Dictionary<int, string>();
			dictionary = InsertDataManager.ReadExtensibleStorage(this.m_doc);
			if (dictionary == null)
			{
				return;
			}
			this.ResultGrid.Cols = this.m_nMostColNum + dictionary.Count;
			this.m_nMostColNum = this.ResultGrid.Cols;
			foreach (KeyValuePair<int, string> keyValuePair in dictionary)
			{
				int num3 = 2;
				this.m_lstAddCols.Add(keyValuePair.Key);
				foreach (string text in StrEscapeTool.UnEsapeAneUnMerge(keyValuePair.Value))
				{
					if (Untiltiy.m_lstNoInitRow.Contains(num3))
					{
						num3++;
					}
					else
					{
						this.ResultGrid.Cell(num3, keyValuePair.Key).Text = text;
						num3++;
					}
				}
			}
		}

		private int GetTableColNum()
		{
			int num = 0;
			int num2 = 0;
			for (int i = 4; i < this.ResultGrid.Cols; i++)
			{
				if (this.ResultGrid.Cell(2, i).Text == "")
				{
					num = i;
					break;
				}
			}
			for (int j = 4; j < this.ResultGrid.Cols; j++)
			{
				if (this.ResultGrid.Cell(12, j).Text == "")
				{
					num2 = j;
					break;
				}
			}
			if (num2 == 0)
			{
				num2 = this.ResultGrid.Cols - 1;
			}
			if (num > num2)
			{
				return num;
			}
			return num2;
		}

		private void ShowSubArea(int nRow, int nCol, BaseCellData CurCellData)
		{
			this.tvSubArea.Nodes.Clear();
			TreeNode treeNode = null;
			BaseCellData baseCellData;
			if (CurCellData == null)
			{
				baseCellData = this.tableManager.GetCellData(nRow, nCol);
			}
			else
			{
				baseCellData = CurCellData;
			}
			if (baseCellData == null)
			{
				this.lbrowInfo.Visible = false;
				this.lbRowVal.Visible = false;
				this.groupBox1.Visible = false;
				this.tvSubArea.Visible = false;
				this.ClearAttributeTable();
				return;
			}
			if (!Untiltiy.m_lstBaseDataRow.Contains(baseCellData.RowNum))
			{
				this.ClearAttributeTable();
				this.lbrowInfo.Text = this.GetExportDataFormula(nRow);
				if (baseCellData.CellValue.Length > 7)
				{
					int y = this.lbRowVal.Location.Y;
					int num = int.Parse((15 * baseCellData.CellValue.Length).ToString());
					this.lbRowVal.Location = new System.Drawing.Point(106 - (num - 106), y);
				}
				this.lbRowVal.Text = baseCellData.CellValue;
			}
			else
			{
				if (this.ResultGrid.Cell(nRow, nCol).BackColor == System.Drawing.Color.Gainsboro)
				{
					this.lbrowInfo.Visible = true;
					this.lbRowVal.Visible = true;
					this.groupBox1.Visible = true;
					this.tvSubArea.Visible = false;
					this.lbrowInfo.Text = Untiltiy.m_strCustomText;
					this.lbRowVal.Text = this.ResultGrid.Cell(nRow, nCol).Text;
					if (this.lbRowVal.Text.Length > 7)
					{
						int y2 = this.lbRowVal.Location.Y;
						int num2 = int.Parse((15 * this.lbRowVal.Text.Length).ToString());
						this.lbRowVal.Location = new System.Drawing.Point(106 - (num2 - 106), y2);
					}
					return;
				}
				if (baseCellData is TotalTargetData)
				{
					treeNode = new TreeNode(baseCellData.CurUseAreaPlan.Name);
					treeNode.Tag = baseCellData;
					this.tvSubArea.Nodes.Add(treeNode);
					using (List<ElementId>.Enumerator enumerator = baseCellData.LstRoom.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							ElementId elementId = enumerator.Current;
							Room room = this.m_doc.GetElement(elementId) as Room;
							TreeNode treeNode2 = new TreeNode(room.Name.Split(new char[]
							{
								' '
							}).First<string>() + " " + this.GetRoomNum(room));
							treeNode2.Tag = room;
							this.tvSubArea.Nodes[0].Nodes.Add(treeNode2);
						}
						goto IL_47C;
					}
				}
				if (baseCellData is HouseTargetData)
				{
					treeNode = new TreeNode((baseCellData as HouseTargetData).HouseNum);
					treeNode.Tag = baseCellData;
					this.tvSubArea.Nodes.Add(treeNode);
					using (List<ElementId>.Enumerator enumerator = baseCellData.LstRoom.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							ElementId elementId2 = enumerator.Current;
							Room room2 = this.m_doc.GetElement(elementId2) as Room;
							TreeNode treeNode3 = new TreeNode(room2.Name.Split(new char[]
							{
								' '
							}).First<string>() + " " + this.GetRoomNum(room2));
							treeNode3.Tag = room2;
							this.tvSubArea.Nodes[0].Nodes.Add(treeNode3);
						}
						goto IL_47C;
					}
				}
				if (baseCellData is CoverTargetData)
				{
					treeNode = new TreeNode(this.ResultGrid.Cell(12, nCol).Text);
					treeNode.Tag = baseCellData;
					this.tvSubArea.Nodes.Add(treeNode);
					foreach (ElementId elementId3 in baseCellData.LstRoom)
					{
						Room room3 = this.m_doc.GetElement(elementId3) as Room;
						TreeNode treeNode4 = new TreeNode(room3.Name.Split(new char[]
						{
							' '
						}).First<string>() + " " + this.GetRoomNum(room3));
						treeNode4.Tag = room3;
						this.tvSubArea.Nodes[0].Nodes.Add(treeNode4);
					}
				}
				IL_47C:
				this.tvSubArea.SelectedNode = treeNode;
				this.ShowAttributeTable(treeNode.Tag as BaseCellData);
			}
			this.tvSubArea.Refresh();
			this.tvSubArea.ExpandAll();
		}

		private string GetExportDataFormula(int nCurClickRow)
		{
			string result = string.Empty;
			switch (nCurClickRow)
			{
			case 5:
				result = "各层建筑面积*楼层层数";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 6:
				result = "标高大于等于±0的楼层\n建筑面积之和";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 7:
				result = "标高小于±0的楼层建筑\n面积之和";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 8:
				result = "地上建筑面积+地下建筑\n面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 9:
				result = "∑套内面积*建筑包含的\n各种户型数量";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 10:
				result = "总建筑面积-总套内面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 19:
				result = "半面积区域之和";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 20:
				result = "总套内面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 21:
				result = "套内面积-所有墙体面积\n-半阳台面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 22:
				result = "所有套内使用面积之和";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 25:
				result = "套型面积+赠送面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 26:
				result = "套内面积+公共公摊面积\n+楼层公摊面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 27:
				result = "套内面积/总套内面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 28:
				result = "套内面积/总套内建筑面\n积*单元公共公摊面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 29:
				result = "套内面积/所在楼层的\n总套内面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			case 30:
				result = "套内面积/所在楼层的\n总套内面积*（楼层面积\n-所在楼层的总套内面积）";
				this.lbRowVal.Location = new System.Drawing.Point(106, 57);
				this.groupBox1.Location = new System.Drawing.Point(5, 73);
				break;
			case 32:
				result = "赠送面积/套型面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 33:
				result = "总使用面积/总套型面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 34:
				result = "套内面积/套型面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 35:
				result = "总使用面积/总销售面积";
				this.lbRowVal.Location = new System.Drawing.Point(106, 27);
				this.groupBox1.Location = new System.Drawing.Point(5, 43);
				break;
			case 36:
				result = "套内面积/（套型面积+\n赠送面积）";
				this.lbRowVal.Location = new System.Drawing.Point(106, 42);
				this.groupBox1.Location = new System.Drawing.Point(5, 58);
				break;
			}
			return result;
		}

		private string GetRoomNum(Room inputRoom)
		{
			string result = "";
			foreach (object obj in inputRoom.Parameters)
			{
				Parameter parameter = (Parameter)obj;
				if (parameter != null && parameter.Definition.Name == "房间编号")
				{
					IList<Parameter> parameters = inputRoom.GetParameters("房间编号");
					if (parameters.Count != 0)
					{
						string text = parameters[0].AsInteger().ToString();
						if (text != "")
						{
							result = text;
							break;
						}
					}
				}
			}
			return result;
		}

		private void ShowAttributeTable(BaseCellData inputCellData)
		{
			if (inputCellData == null || inputCellData.CurUseAreaPlan == null)
			{
				return;
			}
			if (inputCellData is TotalTargetData)
			{
				this.AttributeTableShow.Cell(1, 2).Text = Untiltiy.m_strTotalArchArea;
			}
			else
			{
				this.AttributeTableShow.Cell(1, 2).Text = Untiltiy.m_strTotalInnerArea;
			}
			this.AttributeTableShow.Cell(2, 2).Text = inputCellData.CurUseAreaPlan.Name;
			this.AttributeTableShow.Cell(2, 2).WrapText = true;
			this.AttributeTableShow.Cell(3, 2).Text = inputCellData.CurUseAreaPlan.GenLevel.Name;
			this.AttributeTableShow.Cell(3, 2).WrapText = true;
			if (Untiltiy.m_lstBaseDataInUnit.Contains(inputCellData.RowNum))
			{
				this.AttributeTableShow.Cell(4, 2).Text = this.ResultGrid.Cell(5, inputCellData.ColumnNum).Text;
			}
			else if (Untiltiy.m_lstBaseDataInHouse.Contains(inputCellData.RowNum))
			{
				this.AttributeTableShow.Cell(4, 2).Text = this.ResultGrid.Cell(15, inputCellData.ColumnNum).Text;
			}
			else
			{
				this.AttributeTableShow.Cell(4, 2).Text = inputCellData.CellValue;
			}
			this.AttributeTableShow.Refresh();
		}

		private bool ShowAreaPlan(DoType type)
		{
			try
			{
				BaseCellData cellData = this.tableManager.GetCellData(this.m_nModifyCellRow, this.m_nModifyCellCol);
				if (!Untiltiy.m_lstBaseDataRow.Contains(this.m_nModifyCellRow) || cellData == null)
				{
					if (type == DoType.DT_Modify)
					{
						YJKMessageBox.Show("请选择基础数据进入修改。");
					}
					else
					{
						YJKMessageBox.Show("请选择基础数据进入查看。");
					}
					return false;
				}
				this.UiDoc.ActiveView = cellData.CurUseAreaPlan;
			}
			catch (Exception)
			{
				return false;
			}
			return true;
		}

		private void ClearAttributeTable()
		{
			this.AttributeTableShow.Cell(1, 2).Text = "";
			this.AttributeTableShow.Cell(2, 2).Text = "";
			this.AttributeTableShow.Cell(3, 2).Text = "";
			this.AttributeTableShow.Cell(4, 2).Text = "";
		}

		private bool BeInteger(string textValue)
		{
			bool result = true;
			try
			{
				if (textValue.First<char>() == '.')
				{
					return false;
				}
				foreach (char c in textValue.ToCharArray())
				{
					if (c != '.')
					{
						try
						{
							Convert.ToInt32(c.ToString());
						}
						catch (Exception)
						{
							result = false;
							break;
						}
					}
				}
			}
			catch (Exception)
			{
				return false;
			}
			return result;
		}

		private bool IfExistIllegalVal()
		{
			if (!Untiltiy.m_lstBanDoubleClickRow.Contains(this.m_nClickCellRow))
			{
				return false;
			}
			Cell cell = this.ResultGrid.Cell(this.m_nClickCellRow, this.m_nClickCellCol);
			if (cell != null && cell.Text != null && !this.BeInteger(cell.Text))
			{
				YJKMessageBox.Show("存在非法数值, 请检查表格数据!");
				return true;
			}
			foreach (int row in Untiltiy.m_lstBanDoubleClickRow)
			{
				for (int i = 4; i < this.ResultGrid.Cols; i++)
				{
					if (this.ResultGrid.Cell(row, i).BackColor == System.Drawing.Color.Gainsboro)
					{
						cell = this.ResultGrid.Cell(row, i);
						if (cell != null && cell.Text != null && !this.BeInteger(cell.Text))
						{
							YJKMessageBox.Show("存在非法数值, 请检查表格数据!");
							return true;
						}
					}
				}
			}
			return false;
		}

		private void RefreshCellData(double dBeforeModifyVal, List<Area> lstNewArea, List<Room> lstSelectRoom)
		{
			double num = 0.0;
			double num2 = 0.0;
			foreach (Area area in lstNewArea)
			{
				num += area.Area;
			}
			double num3 = 0.0;
			try
			{
				num3 = double.Parse(this.ResultGrid.Cell(this.m_nModifyCellRow, this.m_nModifyCellCol).Text);
			}
			catch (Exception)
			{
			}
			if (Untiltiy.m_lstOnlyNeedAddVal.Contains(this.m_nModifyCellRow))
			{
				num2 += num - dBeforeModifyVal;
			}
			else
			{
				num2 = num;
			}
			BaseCellData cellData = this.tableManager.GetCellData(this.m_nModifyCellRow, this.m_nModifyCellCol);
			cellData.CellValue = (AreaCalcManager.ChangeAreaByUnit(num2) + num3).ToString("f2");
			if (this.m_nModifyCellRow == 4)
			{
				string text = this.ResultGrid.Cell(this.m_nModifyCellRow, 2).Text;
				string text2 = this.ResultGrid.Cell(2, this.m_nModifyCellCol).Text;
				this.lstRecordCells.Add(new List<string>
				{
					text,
					text2,
					cellData.CellValue
				});
			}
			if (lstSelectRoom.Count != 0)
			{
				foreach (Room room in lstSelectRoom)
				{
					cellData.LstRoom.Add(room.Id);
				}
			}
			List<BaseCellData> updateCellData = this.tableManager.GetUpdateCellData(cellData);
			updateCellData.Add(cellData);
			foreach (BaseCellData baseCellData in updateCellData)
			{
				this.ResultGrid.Cell(baseCellData.RowNum, baseCellData.ColumnNum).Text = baseCellData.CellValue;
			}
			this.ShowAttributeTable(cellData);
			this.ShowSubArea(this.m_nModifyCellRow, this.m_nModifyCellCol, cellData);
		}

		private ExternalCommandData m_revit;

		public Document m_doc;

		private List<ElementId> lstSaveSingleCv = new List<ElementId>();

		private List<ElementId> lstDeleteCv = new List<ElementId>();

		private List<Area> lstNewArea = new List<Area>();

		private List<int> m_lstAddCols = new List<int>();

		private UIDocument m_uiDoc;

		private bool m_bIfContinue;

		private bool m_bIfBreak = true;

		private bool m_bIfManuEsc = true;

		private IWin32Window m_revitHandle;

		private AreaStatisticResultForm.BeforeContinueMethod m_useBeforeCotinueMethod;

		private AreaStatisticResultForm.BeforeCloseMethod m_useBeforeCloseMethodMethod;

		private SelectAreaManager controller;

		private TableDataManager tableManager;

		private string m_strCellText = string.Empty;

		private int m_nClickCellRow;

		private int m_nModifyCellRow;

		private int m_nClickCellCol;

		private int m_nModifyCellCol;

		private int m_nMostColNum;

		private GridSetCommonInfo m_gridSet = new GridSetCommonInfo();

		public Dictionary<int, List<string>> m_lstaddColData = new Dictionary<int, List<string>>();

		private List<List<string>> lstRecordCells = new List<List<string>>();

		private delegate void BeforeContinueMethod();

		private delegate void BeforeCloseMethod();
	}
}
